<template>
  <div class="account">
    <vue-particles
        class="login-bg backBox"
        color="#a8b0e1"
        :particleOpacity="0.7"
        :particlesNumber="100"
        shapeType="circle"
        :particleSize="4"
        linesColor="#a8b0e1"
        :linesWidth="1"
        :lineLinked="true"
        :lineOpacity="0.4"
        :linesDistance="150"
        :moveSpeed="3"
        :hoverEffect="true"
        hoverMode="grab"
        :clickEffect="false"
        clickMode="push"
    />
    <div class="headTop" @click="onClickLeft">
      <van-icon name="arrow-left"/>
    </div>
    <h3>账号密码登录</h3>
    <van-form validate-first @failed="onFailed" @submit="submit">
      <div class="itemInput">
        <van-field
            v-model="valuetext"
            name="validatorText"
            label="账号"
            placeholder="账号"
            :rules="[{ required: true ,message: '请填写用户名' }]"
        />
      </div>
      <div class="passInput itemInput">
        <van-field
            v-model="valuepass"
            :type="eyeShow?'text':'password'"
            name="密码"
            label="密码"
            placeholder="请输入密码"
            :rules="[{ required: true, message: '请输入格式正确的密码' }]"
        />
        <div class="passEyE" @click="onEyE">
          <van-icon v-show="!eyeShow" name="closed-eye"/>
          <van-icon v-show="eyeShow" name="eye-o"/>
        </div>
      </div>

      <div class="defl SwitchPages">
        <router-link tag="p" to="/phonesign">验证码登录</router-link>
        <div>
          <router-link tag="span" to="/register">去注册?</router-link>
          /
          <router-link tag="span" to="/forgotpassword">忘记密码</router-link>
        </div>
      </div>
      <div>
        <van-button round block type="info" native-type="submit">登 录</van-button>
      </div>

    </van-form>
  </div>
</template>

<script>
import {Toast} from "vant";
import {AccounsSign} from "@/api/api";

export default {
  name: "ccountSign",
  data() {
    return {
      eyeShow: false,
      valuetext: '',
      valuepass: '',
      // specialCharacters : RegExp(/[~!@#$%^&*()\-\=·！@#￥%……&*（）——+]+/),
      white: RegExp(/\s/),
      flagFlas: true,
      count:0,
      // clickEffect:true
    }
  },
  methods: {
    preventDefault(e){
      e.preventDefault()
    },
    // preventClick(){
    //   this.count++
    //   if(this.count>=5){
    //     console.log(this.clickEffect)
    //     this.clickEffect = false
    //   }
    // },
    //小眼睛
    onEyE() {
      this.eyeShow = !this.eyeShow
    },
    onClickLeft() {
      // Toast('返回');
      this.$router.go(-1)
    },
    onFailed(errorInfo) {
      console.log('failed', errorInfo);
    },
    //  账号验证
    validator(value) {
      if (value) {
        let a_reg = RegExp(/^[a-zA-Z0-9]$/)
        let b_reg = RegExp(/[~!@#$%^&*()\-=·@#￥%……&*（）、‘”'"[]{}——+]+/)
        let c_reg = RegExp(/\s/)
        let d_reg = RegExp(/^[u4e00-u9fa5_a-zA-Z0-9]+$/)
        if (a_reg.test(value)) {
          Toast('格式错误');
          return false
        } else if (b_reg.test(value)) {
          Toast('不能为特殊字符');
          return false
        } else if (c_reg.test(value)) {
          Toast('不能为空格');
          return false
        } else if (value.replace(/[^x00-xff]/g, 'xx').length < 6 || value.replace(/[^x00-xff]/g, 'xx').length > 20) {
          Toast('用户名不得小于6个或大于20个字符!');
          return false
        } else if (!d_reg.test(value)) {
          Toast('不能为汉字')
          return false
        } else {
          return true
        }
      } else {
        Toast('请填写账号');
        return false
      }
    },


    submit() {
      //账号密码接口
      AccounsSign(this.valuetext, this.valuepass).then(res => {
        if (res.data.code == 0 || res.data.status == 200) {
          console.log(res.data)
          this.$store.state.isLogin = true
          this.$store.commit('getUserInfo', res.data.data)
          Toast(res.data.msg);
          this.$router.push({path: '/index'})

        } else {
          let reg = /[\u4e00-\u9fa5]/
          if (reg.test(res.data.msg)) {
            Toast(res.data.msg);
          } else {
            Toast('账号或密码不正确');
          }
        }
      }).catch(() => {
        Toast('网络错误')
      })
    },
  },
}
</script>


<style scoped lang="less">

.account {
  padding: 0 18px;
  background-color: rgb(255,255,255);

  //背景图
  .backBox {
    position: absolute;
    background-color: rgb(255,255,255);
    height: 100vh;
    z-index: -1;
    left: 0;
    top: 0;
    width: 100vw;
  }

  //密码小眼睛
  .passInput {
    position: relative;

    .passEyE {
      position: absolute;
      top: 8px;
      right: 30px;
      width: 31px;
      height: 29px;
      //border: 1px solid red;
      i {
        font-size: 20px;
      }
    }
  }

  .headTop {
    margin-top: 33px;

    i {
      font-size: 22px;
    }
  }

  h3 {
    margin-top: 33px;
    margin-bottom: 54px;
    color: #EC0D0D;
    font-size: 28px;
  }

  .itemInput:nth-child(1) {
    border-radius: 9px 9px 0 0;;
  }

  .itemInput:nth-child(2) {
    border-radius: 0 0 9px 9px;;
  }

  .itemInput {
    position: relative;
    overflow: hidden;

    input {
      width: 100%;
      background-color: #F8F8F8;
      border: 0;
      text-indent: 25px;
      height: 50px;
      line-height: 50px;
    }

    .eyeDiv {
      position: absolute;
      top: 32%;
      right: 8%;
    }

    .p {
      height: 25px;
      line-height: 25px;
      color: red;

    }
  }

  .SwitchPages {
    font-size: 14px;
    color: #BDBDBD;
    margin-top: 25px;
    margin-bottom: 30px;

  }

  .buttonSign {
    text-align: center;
    width: 80%;
    height: 40px;
    line-height: 40px;
    color: white;
    background-color: #FF0000;
    margin: auto;
    border-radius: 22px;
  }
}
</style>